package com.gfxy.modules.common.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gfxy.modules.common.entity.MemberList;
import com.gfxy.modules.common.mapper.MemberListMapper;
import com.gfxy.modules.common.service.IMemberListService;
import com.gfxy.modules.common.service.ScoreUpdate;
import com.gfxy.modules.system.entity.SysUser;
import com.gfxy.modules.system.mapper.SysUserMapper;
import org.springframework.stereotype.Service;

import java.util.List;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @Description: 成员列表
 * @Author: jeecg-boot
 * @Date:   2021-06-29
 * @Version: V1.0
 */
@Service
public class MemberListServiceImpl extends ServiceImpl<MemberListMapper, MemberList> implements IMemberListService {
	@Autowired
	ScoreUpdate scoreUpdate;
	@Autowired
	private MemberListMapper memberListMapper;

	@Autowired
	private SysUserMapper userMapper;




	@Override
	public List<MemberList> selectByItemId(String mainId) {
		return memberListMapper.selectByItemId(mainId);
	}

	public List<SysUser> selectUserLikeRealName(String realName){
		QueryWrapper<SysUser> queryWrapper = new QueryWrapper();
		queryWrapper.eq("realname", realName);
		List<SysUser> result = userMapper.selectList(queryWrapper);
		return result;
	}

	@Override
	public List<SysUser> selectAllUser() {
		QueryWrapper<SysUser> queryWrapper = new QueryWrapper();
		List<SysUser> result = userMapper.selectList(queryWrapper);
		return result;
	}




	@Override
	public List<MemberList> selectByRealName(String realName) {

		return memberListMapper.selectByRealName(realName);
	}



	@Override
	public boolean deleteByItemId(String dateId) {
		List<MemberList> memberList = this.selectByItemId(dateId);
		this.memberListMapper.deleteByItemId(dateId);
		memberList.forEach(result->{
			scoreUpdate.updataNewScore(result);
		});


		return false;
	}

	@Override
	public boolean saveList(String id, List<MemberList> memberLists) {
		if(memberLists!=null) {
			for (MemberList memberList : memberLists) {
				memberList.setItemId(id);
				memberList.setIsPass(0);
			}
			this.saveBatch(memberLists);
			memberLists.forEach(result->{
				scoreUpdate.updataNewScore(result);
			});
		}
		return true;
	}

	@Override
	public List<MemberList> getMemberListByUserIdAndDate(String workNo, String date, String projectId,String classificationId) {


		return this.memberListMapper.selectByDateAndTeacherIdAndClassificationId(workNo,date,projectId,classificationId);
	}

	@Override
	public List<MemberList> getMemberListByOrgId(String orgId) {
		List<MemberList> memberLists= baseMapper.getMemberListByOrgId(orgId);
		for (int i = 0; i < memberLists.size(); i++) {
			MemberList memberList = memberLists.get(i);
			memberList.setItemId("33");
			memberList.setRanked(i+1);
			memberList.setIsCustom(1);
			memberList.setScore(0.0);
		}
		return memberLists;
	}


//	public List<MemberList> getMemberList(String id) {
//		QueryWrapper<MemberList> projectId = new QueryWrapper<MemberList>().eq("item_id", id);
//		return this.baseMapper.selectList(projectId);
//	}

}
